package com.sky.controller.admin;


import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.ViolationReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;


@RestController("adminReportController")
@RequestMapping("/admin/report")
@Slf4j
@Api(tags = "管理端数据统计相关接口")
public class ReportController {
    @Autowired
    private ReportService reportService;

    @GetMapping("/export")
    @RequiresRoles(value={"管理员","系统管理员"},logical = Logical.OR)
    @ApiOperation("导出数据")
    public void export(HttpServletResponse response){
        reportService.exportBusinessData(response);
    }

    /**
     * 违法记录统计
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/violationStatistics")
    @RequiresRoles(value={"管理员","系统管理员"},logical = Logical.OR)
    @ApiOperation("违法记录统计")
    public Result<ViolationReportVO> violationStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("违法记录数据统计：{}到{}", begin, end);
        ViolationReportVO data = reportService.getViolationStatistics(begin, end);
        return Result.success(data);
    }
    /**
     * 违法类型饼图
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/violationPie")
    @RequiresRoles(value={"管理员","系统管理员"},logical = Logical.OR)
    @ApiOperation("违法类型饼图")
    public Result<ViolationReportVO> violationPie(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("违法类型饼图：{}到{}", begin, end);
        ViolationReportVO data = reportService.getViolationPie(begin, end);
        return Result.success(data);
    }
}
